package com.java.demo.data;

/**
 * @auther zhangwj
 * @date 2020/7/14 11:11 上午
 */
public class Demo2 {


    public static void main(String[] args) {
        int size = 4;
        int length = 2 * size - 2 + 1;
        int[][] data = getData(size);
        int sum = 0;
        int x = 0;
        int y = 0;
        for (int i = 0; i < length; i++) {
            if (i == 0) {
                sum += data[x][y];
                continue;
            }
            int t1 = x + 1;
            int t2 = y + 1;
            if (t1 >= size) {
                sum += data[x][y + 1];
                continue;
            }
            if (t2 >= size) {
                sum += data[x + 1][y];
                continue;
            }
            int num1 = data[x + 1][y];
            int num2 = data[x][y + 1];
            if (num1 > num2) {
                sum += num2;
                y += 1;
            } else {
                sum += num1;
                x += 1;
            }
            System.out.println("num=" + data[x][y]);
        }
        System.out.println(sum);
    }

    private static int[][] getData(int size) {
        int[][] data = {{4, 1, 5, 3}, {3, 2, 7, 7}, {6, 5, 2, 8}, {8, 9, 4, 4}};
        return data;
    }
}
